﻿using NHibernate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Api.util
{
    class SessionFactory
    {
   private volatile static ISessionFactory _instance = null;
    private static readonly object lockHelper = new object();
    private SessionFactory() { }
    public static ISessionFactory CreateInstance()
    {
        if(_instance == null)
        {
            lock(lockHelper)
            {
                if (_instance == null) {
                    var cfg = new NHibernate.Cfg.Configuration().Configure(AppDomain.CurrentDomain.BaseDirectory+"Config/hibernate.cfg.xml");
                    _instance = cfg.BuildSessionFactory();
                }

            }
        }
        return _instance;
     }
    }
}
